package com.ludomancy.timescape;

import java.util.Properties;

import com.ludomancy.gamelib.DataStorage;
import com.ludomancy.gamelib.GameApplet;
import com.ludomancy.gamelib.Sound;

public class TimescapeApplet extends GameApplet
{
	public static TimescapeWidget mainWidget;
	public static TimescapeApplet app;
	
	public void init()
	{
		super.init(new GameTheme());
		app = this;
		
		// preloading
		Sound.soundActivated = true;
		
		// should we load a savegame?
		try
		{
//			Properties props = DataStorage.load("starwave");
//			String levelString = (String)props.get("level");
		}
		catch(Exception e)
		{
		}
		resetGame(true, null);
	}
	
	public void resetGame(boolean showBriefing, int[][] initialSetup)
	{
		// create the game
		new Game(getBounds().width, getBounds().height - TimescapeWidget.STATUS_BAR_HEIGHT);
		
		// create the UI
		gameCanvas.destroyWidget(mainWidget);
		mainWidget = new TimescapeWidget(null, getBounds(), initialSetup, showBriefing);
		gameCanvas.showWidget(mainWidget);
	}
	
	public void restart()
	{
		saveData();
		resetGame(true, null);
	}
	
	private void saveData()
	{
		// save level
		Properties props = new Properties();
		DataStorage.save("starwave", props);		
	}
}
